package com.bw.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.bw.bean.ylq.Interview;
import com.bw.bean.ylq.Student;
import com.bw.service.IYlqService;


/**
 * 2017-3-27
 * 姚力琪
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/ylq")
public class YlqController {
	
	@Autowired
	private IYlqService service;
	
	/**
	 * 跳转添加面试页面
	 * @return
	 */
	@RequestMapping("/toAddInterview")
	public ModelAndView interview(Integer iid,Integer sid)throws Exception{
		Map<String, Object> map = new HashMap<String,Object>();
		//通过学生编号获取学生信息（班级名称）
		Student student = service.selectStudentById(sid);
		map.put("student", student);
		
		//获取当前时间
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String format = simpleDateFormat.format(new Date());
		map.put("date", format);
		ModelAndView view = new ModelAndView();
		view.setViewName("ylq/addInterview");
		view.addAllObjects(map);
		return view;
	}
	
	/**
	 * 添加面试信息
	 */
	@RequestMapping("addInterview")
	@ResponseBody
	public boolean addInterview(Interview interview){
		try {
			service.addInterview(interview);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
}
